<?php
// +----------------------------------------------------------------------
// | ThinkSNS
// +----------------------------------------------------------------------
// | Copyright (c) 2008 http://www.thinksns.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: Nonant <nonant@163.com>
// +----------------------------------------------------------------------

class IndexAction extends BaseAction  {
	
	function _initialize(){
		parent::_initialize();		
	}	
	
	function index(){
		$pBug = D('Bug');
		if(isset($_GET['state']) && $_GET['state']!='all') $map['state'] = intval($_GET['state']);
		$list = $pBug->where($map)->order('cTime DESC')->findpage(12);
		$this->assign($list);
		$this->display();
	}
	

	
	function my(){
		$map['uid'] = $this->mid;
		$pBug = D('Bug');
		if(isset($_GET['state']) && $_GET['state']!='all') $map['state'] = intval($_GET['state']);
		$list = $pBug->where($map)->order('cTime DESC')->findpage(12);
		$this->assign($list);		
		$this->display();
	}
	
	function manage(){
		if(! $this->_isbugadmin){
			$this->error('您不是管理员');
		}
		
		$intUid = intval($_GET['uid']);
		$pBugCoopt = D('BugCoopt');
		$map= 'a.uid='.(($intUid)?$intUid:$this->mid);
		if(isset($_GET['state']) && $_GET['state']!='all'){
			$map.=' AND b.state='.intval($_GET['state']);
		}

		$count = $pBugCoopt->query("SELECT count(b.id) as c FROM ts_bug_coopt a RIGHT JOIN ts_bug b on a.bugid=b.id WHERE ".$map);

		//import('ORG.Util.Page');
		$count	=	$count[0]['c'];
		$rows	=	12;
		$p		=	 new Page($count,$rows);
		$list = $pBugCoopt->query("SELECT a.douid,a.cTime as dotime,b.* FROM ts_bug_coopt a RIGHT JOIN ts_bug b on a.bugid=b.id WHERE ".$map." ORDER by dotime DESC LIMIT {$p->firstRow},{$p->listRows}");
		$page	=	$p->show();
		$this->assign('html',$page);
		$this->assign('list',$list);
		$this->display();
	}
	
	function search(){
		$pBug = D('Bug');
		$keywords = trim($_REQUEST['keywords']);
		if(empty($keywords)){
			$this->error('搜索内容不能为空');
		}else{
			$map['title'] = array("like","%".$keywords."%");
			$list = $pBug->where($map)->order('cTime DESC')->findpage();
			$this->assign('keywords',$keywords);
			$this->assign($list);		
			$this->display();
		}
	}
}
?>